package tech.aistar.wyymusicplayer.mapper;

import org.apache.ibatis.annotations.*;
import tech.aistar.wyymusicplayer.pojo.User;


import java.util.List;

public interface UserMapper {
    @Select("select * from users ")
    List<User> findAll();

    @Select("select * from users where email=#{value}")
    User getByEmail(String email);


    @Select("select * from users where id=#{userId}")
    User getById(Integer userId);

    /**
     * 根据id进行删除
     * @param id 用户的id
     * @return 受影响的行数,比如成功删除了一行,返回数字1.  如果删除失败,则返回数字0
     */
    @Delete("delete from users where id=#{value}")
    int delById(Integer id);

    @Select("select * from users where username=#{username}}")
    User findByUsernameAndPassword(@Param("username") String username);

    @Select("select is_default_username from users where username=#{username}")
    boolean isDefaultUsername(@Param("username") String username);
    @Insert("insert into users values(#{username})")
    boolean InsertUser(@Param("username") String username);

    @Insert("INSERT INTO users (email, user_level) VALUES (#{email}, #{userLevel})")
    boolean InsertMail(@Param("email") String email,@Param("userLevel") Integer userLevel);


    // 更新用户名
    @Update("UPDATE users SET username = #{newUsername} WHERE id = #{userId}")
    int updateUsername(@Param("userId") Integer userId, @Param("newUsername") String newUsername);
    @Update("UPDATE users SET is_default_username = #{isDefaultUsername} WHERE id = #{userId}")
    boolean UpdataIsDefaultUsername(@Param("isDefaultUsername") Integer isDefaultUsername,@Param("userId") Integer userId);
    // 检查用户名是否存在
    @Select("SELECT COUNT(*) FROM users WHERE username = #{username}")
    boolean existsByUsername(String username);
}
